<%@ page language="java" autoFlush="true"%>
<%@ page import="org.unitime.timetable.webutil.timegrid.ExamGridTable" %>
<%@ page import="org.unitime.commons.Debug" %>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tld/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/tld/timetable.tld" prefix="tt" %>
<script language="JavaScript" type="text/javascript" src="scripts/block.js"></script>
<tiles:importAttribute />
<html:form action="/examGrid">
<%
try {
%>
	<script language="JavaScript">blToggleHeader('Filter','dispFilter');blStart('dispFilter');</script>
	<TABLE width="100%" border="0" cellspacing="0" cellpadding="3">
		<TR>
			<TD width="10%" nowrap>Mostrar clases/cursos:</TD>
			<TD>
				<html:checkbox property="showSections"/>
			</TD>
		</TR>
		<TR>
  			<TD nowrap>Problema de examen:</TD>
			<TD>
				<html:select property="examType" onchange="javascript: showDates(this.value);">
					<html:optionsCollection property="examTypes" label="label" value="value"/>
				</html:select>
			</TD>
		</TR>
		<TR>
			<TD>Recursos:</TD>
			<TD>
				<html:select property="resource">
					<html:optionsCollection name="examGridForm" property="resources" label="label" value="value"/>
				</html:select>
			</TD>
		</TR>
		<TR>
			<TD>Filtro:</TD>
			<TD>
				<html:text property="filter" maxlength="1000" size="40"/>
			</TD>
		</TR>
		<logic:iterate name="examGridForm" property="examTypes" id="et">
			<bean:define name="et" property="value" id="examType"/>
			<TR id='<%="daterow."+examType%>'>
				<TD>Fecha:</TD>
				<TD>
					<html:select property='<%="date["+examType+"]"%>'>
						<html:optionsCollection name="examGridForm" property='<%="dates["+examType+"]"%>' label="label" value="value"/>
					</html:select>
				</TD>
			</TR>
			<TR id='<%="timerow."+examType%>'>
				<TD>Hora:</TD>
				<TD>
					<html:select property='<%="startTime["+examType+"]"%>'>
						<html:optionsCollection name="examGridForm" property='<%="startTimes["+examType+"]"%>' label="label" value="value"/>
					</html:select>
					-
					<html:select property='<%="endTime["+examType+"]"%>'>
						<html:optionsCollection name="examGridForm" property='<%="endTimes["+examType+"]"%>' label="label" value="value"/>
					</html:select>
				</TD>
			</TR>
		</logic:iterate>
		<script language="JavaScript" type="text/javascript">
			function showDates(examType) {
				var idx = 0;
				while (document.getElementById("daterow."+idx)!=null) {
					var disp = (idx==examType?null:"none");
					document.getElementById("daterow."+idx).style.display=disp;
					document.getElementById("timerow."+idx).style.display=disp;
					idx++;
				}
			}
			showDates(document.getElementsByName('examType')[0].value);
		</script>
		<TR>
			<TD>Mostrar modo:</TD>
			<TD>
				<html:select property="dispMode">
					<html:optionsCollection name="examGridForm" property="dispModes" label="label" value="value"/>
				</html:select>
			</TD>
		</TR>
		<TR>
			<TD>Antecedentes:</TD>
			<TD>
				<html:select property="background">
					<html:optionsCollection name="examGridForm" property="backgrounds" label="label" value="value"/>
				</html:select>
			</TD>
		</TR>
		<TR>
			<TD>Mostrar preferencias de periodo:</TD>
			<TD>
				<html:checkbox property="bgPreferences"/>
			</TD>
		</TR>
		<TR>
			<TD>Ordenado por:</TD>
			<TD>
				<html:select property="order">
					<html:optionsCollection name="examGridForm" property="orders" label="label" value="value"/>
				</html:select>
			</TD>
		</TR>
		<TR>
			<TD colspan='2' align='right'>
				<html:submit onclick="displayLoading();" property="op" value="Change"/>
				<html:submit onclick="displayLoading();" property="op" value="Export PDF"/>
				<html:submit onclick="displayLoading();" property="op" accesskey="R" value="Refresh"/>
			</TD>
		</TR>
	</TABLE>
	<script language="JavaScript">blEnd('dispFilter');blStartCollapsed('dispFilter');</script>
		<TABLE width="100%" border="0" cellspacing="0" cellpadding="3">
			<TR>
				<TD colspan='2' align='right'>
					<html:submit onclick="displayLoading();" property="op" value="Export PDF"/>
					<html:submit onclick="displayLoading();" property="op" accesskey="R" value="Refresh"/>
				</TD>
			</TR>
		</TABLE>
	<script language="JavaScript">blEndCollapsed('dispFilter');</script>
	<br><br>
	<a name='timetable'></a>
	<TABLE width="100%" border="0" cellspacing="0" cellpadding="3">
		<TR>
			<TD colspan="2">
				<tt:section-header>
					<tt:section-title>
						Horario de examen
					</tt:section-title>
					<A class="l7" href="#legend">Leyenda</A>&nbsp;
				</tt:section-header>
			</TD>
		</TR>
<%
			ExamGridTable table = (ExamGridTable)request.getAttribute("table");
			if (table.models().isEmpty()) { 
%>
				<TR>
					<TD>
						<i>No se han encontrado recursos que coincidan con los criterios.</i>
					</TD>
				</TR>
			</TABLE>
<%
			} else {
%>
			</TABLE>
<%
				table.printToHtml(out);
			}
%>
	<BR>
	<a name='legend'></a>
	<TABLE width="100%" border="0" >
		<TR>
			<TD colspan="3">
				<tt:section-header>
					<tt:section-title>
						Leyenda
					</tt:section-title>
					<A class="l7" href="#timetable">Horario de examen</A>&nbsp;
				</tt:section-header>
			</TD>
		</TR>
<%
			table.printLegend(out);
%>
	</TABLE>
<%
} catch (Exception e) {
	Debug.error(e);
%>		
		<font color='red'><B>Error:<%=e.getMessage()%></B></font>
<%
}
%>
</html:form>